package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.Service.ReportService;
import com.itheima.dao.MemberDao;
import com.itheima.dao.ReportDao;
import com.itheima.uitils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportDao reportDao;
    @Autowired
    private MemberDao memberDao;

    public Map<String, Object> exportBusinessReport() throws Exception {
       Map<String,Object> map = new HashMap<>();

         //获得今天日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        map.put("reportDate",today);

        //获取今天新增会员
        Integer todayNewMember = reportDao.getDateAfterNewMember(today);
        map.put("todayNewMember",todayNewMember);
        
        //查询所有会员数
        Integer totalMember = memberDao.findAll();
        map.put("totalMember",totalMember);

        //获取本周一的日期,获取本周新增会员数
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        Integer thisWeekNewMember = reportDao.getDateAfterNewMember(thisWeekMonday);
        map.put("thisWeekNewMember",thisWeekNewMember);

        //获取本月新增会员数
        String thisMonthFirstDay = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        Integer thisMonthNewMember = reportDao.getDateAfterNewMember(thisMonthFirstDay);
        map.put("thisMonthNewMember",thisMonthNewMember);

        //获取今日预约人数
        Integer todayOrderNumber = reportDao.getDateAfterNewOrder(today);
        map.put("todayOrderNumber",todayOrderNumber);

        //获取今日到诊人数
        Integer todayVisitsNumber = reportDao.getDateAfterNewVisits(today);
        map.put("todayVisitsNumber",todayVisitsNumber);

        //获取本周预约人数
        Integer thisWeekOrderNumber = reportDao.getDateAfterNewOrder(thisWeekMonday);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);

        //获取本周到诊人数
        Integer thisWeekVisitsNumber = reportDao.getDateAfterNewVisits(thisWeekMonday);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);

        //获取本月预约人数
        Integer thisMonthOrderNumber = reportDao.getDateAfterNewOrder(thisMonthFirstDay);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);

        //获取本月到诊人数
        Integer thisMonthVisitsNumber = reportDao.getDateAfterNewVisits(thisMonthFirstDay);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);

        //获取热门套餐数据 List<Map<String,Object>> hotSetmeal
        List<Map<String, Object>> hotSetmeal = reportDao.getHotSetmeal();
        map.put("hotSetmeal",hotSetmeal);

        return map;



    }
}
